#pragma once
#include "../BaseClass.h"

namespace System{
namespace IO{

#ifndef STREAM_BUF_SIZE
#define STREAM_BUF_SIZE 4096
#endif

class FileStream : public XObject
{
private:
	FILE* m_File;

	char m_Buffer[STREAM_BUF_SIZE];
	size_t m_BufLen;
	size_t m_Cursor;

public:
	FileStream(void);
	FileStream(const TCHAR* pFileName, const TCHAR* mode);
	~FileStream(void);

public:
	long GetPosition();
	int Skip(long offset, int origin);
	TCHAR ReadChar();
	size_t Read(void* buffer, size_t elementSize, size_t count);
	System::MemString ReadLine();


private:
	void Init();
	void Close();
	void SubString(char* buffer, size_t start, size_t end);
	bool LoadBuffer();

public:
	VIRTUAL_GET_TYPE();
	VIRTUAL_TOSTRING();
};

DEFINE_CLASS_TYPE(System_IO_FileStream, _T("System::IO::FileStream"));


}
}